//
//  SQLOneViewController.m
//  SQLScrollview
//
//  Created by Mr - 宋 on 2022/7/30.
//

#import "SQLOneViewController.h"
#import "SQLOneCollectionViewCell.h"
@interface SQLOneViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic,strong)UICollectionView *BbtGoodsListCollection;

@end
#define SQLWidth [UIScreen mainScreen].bounds.size.width
#define SQLHeight [UIScreen mainScreen].bounds.size.height
@implementation SQLOneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.BbtGoodsListCollection];
    
    
    self.isCanScroll = NO;
}
- (void)getData{
    NSLog(@"获取数据");
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 20;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    SQLOneCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SQLOneCollectionViewCell" forIndexPath:indexPath];

    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if (!self.isCanScroll) {
        scrollView.contentOffset = CGPointZero;
    }else{
        if (scrollView.contentOffset.y <= 0){
            self.isCanScroll = NO;
            scrollView.contentOffset = CGPointZero;
            if (self.tabTopBlock) {
                self.tabTopBlock();
            }
        }
    }
}

- (UICollectionView *)BbtGoodsListCollection{
    if (!_BbtGoodsListCollection) {
        UICollectionViewFlowLayout *invitaLayout= [[UICollectionViewFlowLayout alloc]init];
        invitaLayout.itemSize = CGSizeMake((SQLWidth-35)/2, (SQLWidth-35)/2+130);
        invitaLayout.minimumInteritemSpacing = 4;
        invitaLayout.minimumLineSpacing = 7;
        invitaLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
        invitaLayout.sectionInset = UIEdgeInsetsMake(2.5, 15, 2.5, 15);
        
        _BbtGoodsListCollection = [[UICollectionView alloc]initWithFrame:CGRectMake(0,0,SQLWidth,SQLHeight) collectionViewLayout:invitaLayout];
        _BbtGoodsListCollection.backgroundColor = [UIColor grayColor];
        _BbtGoodsListCollection.scrollEnabled = YES;
        _BbtGoodsListCollection.scrollsToTop = YES;
        _BbtGoodsListCollection.showsVerticalScrollIndicator = NO;
//        _BbtGoodsListCollection.showsHorizontalScrollIndicator = NO;
        _BbtGoodsListCollection.delegate = self;
        _BbtGoodsListCollection.dataSource = self;
        [_BbtGoodsListCollection registerNib:[UINib nibWithNibName:@"SQLOneCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"SQLOneCollectionViewCell"];
    }
    return _BbtGoodsListCollection;
}

@end
